package com.admin.education.dataTransferObject.integrals.Mapper;

import com.admin.education.dataTransferObject.integrals.IntegralsTransfer;
import com.admin.education.dataTransferObject.userInformation.Mapper.UserInformationMapper;
import com.admin.education.models.Integrals;
import org.mapstruct.*;
import org.mapstruct.factory.Mappers;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Mapper
public abstract class IntegralsMapper {
    @Autowired
    private UserInformationMapper userInformationMapper;

    @Mappings({
            @Mapping(target = "userInformation", ignore = true)
    })
    public abstract IntegralsTransfer mapFrom(Integrals integrals);

    @Mappings({})
    public abstract List<IntegralsTransfer> mapFrom(List<Integrals> integrals);

    @AfterMapping
    public void afterMapping(Integrals integrals, @MappingTarget IntegralsTransfer integralsTransfer) {
        if (null != integrals) {
            integralsTransfer.setUserInformation(userInformationMapper.mapFrom(integrals.getUserInformation()));
        }
    }
}
